// pages/pay/pay.js
Component({
  /**
   * 组件的属性列表
   */
  properties: {

  },

  /**
   * 组件的初始数据
   */
  data: {
    userInfo: {

    },
    pay: [],
    payList: [],
    addressList: [],
    sum: 0,
    num: 0,
    orderid: 0,
    statu: '待付款',
    address: [],
    payArray: []
  },

  /**
   * 组件的方法列表
   */
  methods: {
    onLoad: function (options) {
      // 从options中获取pay1数据  
      let pay1 = JSON.parse(decodeURIComponent(this.options.payArray));

      // 获取存储的userInfo数据  
      const userInfo = wx.getStorageSync('userInfo');

      // 设置数据  
      this.setData({
        payArray: pay1,
        userInfo: userInfo,
      });

      // 打印数据以进行调试  
      console.log(this.data.payArray);
      console.log(userInfo);
    },
    onShow: function () {
      const userInfo = wx.getStorageSync('userInfo');

      if (userInfo) {
        this.setData({
          hasUserInfo: true,
          userInfo: userInfo
        });
      }
    },

    Backto: function () {
      wx.navigateBack({
        delta: 1,
      })
    },

    payto: function () {
      var pay = {
        Time: this.data.payArray[0].time,
        Tony: this.data.payArray[0].tony,
        PriceName: this.data.payArray[0].pricename,
        Price: this.data.payArray[0].price,
        Statu: "已支付",
        CustomerName: this.data.userInfo.nickName
      }
      this.setData({
        ay: pay
      })
      console.log("---------" + this.data.pay)
      wx.request({
          url: 'http://localhost:8080/Pay',
          method: 'post',
          data: {
            Time: this.data.payArray[0].time,
            Tony: this.data.payArray[0].tony,
            PriceName: this.data.payArray[0].pricename,
            Price: this.data.payArray[0].price,
            Statu: "已支付",
            CustomerName: this.data.userInfo.nickName
          },   success: res => {
            if(res.statusCode == 200){  
              wx.navigateTo({  
                url: '../success/register',  
              })  
            }else{  
              console.log('请求失败')  
            }  
            },
       
        }),

        console.log(pay)
      // wx.navigateTo({
      //   url: '../success/register',
      // })
    },

  }
})